# 注意，这一步不是将图像保存为二进制文件，而是将networkx中的图这个数据结构保存为二进制文件。再次加载后由于
# networkx这个库的布局有一定的随机性，因此图的形状会改变，但是图的拓扑关系不会变。
import networkx as nx
import numpy as np
import matplotlib.pyplot as plt
import pickle

G = nx.DiGraph()

G.add_edges_from([('A', 'B'), ('C', 'N'), ('G', 'D')], weight=1)
G.add_edges_from([('D', 'A'), ('D', 'E'), ('B', 'D'), ('D', 'E')], weight=2)
G.add_edges_from([('B', 'C'), ('E', 'F')], weight=3)
G.add_edges_from([('C', 'F')], weight=4)

f = open('savegraph.pickle', 'wb')
pickle.dump(G, f, protocol=pickle.HIGHEST_PROTOCOL)
f.close()
